//
//  SubTopView.swift
//  WalkNovel
//
//  Created by Kevin on 2023/9/1.
//

import UIKit

class SubTopView: UIView {
    
    lazy var bgImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "setting_sub_top"))
        return image
    }()
    
    lazy var sunImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "setting_sub_sun"))
        return image
    }()

    lazy var totleLabel: UILabel = {
        let label = UILabel()
        label.font = .init(name: "Arial-BoldItalicMT", size: 30)
        label.textColor = .white
        label.numberOfLines = 2
        return label
    }()
        
    lazy var checkLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .regular, size: 16)
        label.textAlignment = .center
        label.textColor = .init(named: "black_333333")
        label.numberOfLines = 0
        return label
    }()
    
    lazy var payLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 22)
        label.textColor = .init(named: "red_FE6390")
        return label
    }()
    
    var model: SubModel? {
        didSet {
            if let m = model, let sm = m.sub {
                if m.isDing == 1 {
                    sunImage.isHidden = true
                    if m.checkInOrNOt == 1 {
                        totleLabel.text = "Max:\n\(sm.days*sm.gold)"
                        checkLabel.attributedText = String().wn_textChangeColor("\(m.diffDay) days left\nCheck-in \(m.checkDay) days", "Check-in \(m.checkDay) days", "", .init(named: "red_CD597C")!, .wn_font(name: .bold, size: 18))
                        payLabel.text = "Received \((m.checkDay*sm.gold)) Golds"
                    }else {
                        totleLabel.text = "Max:\n\(sm.days*sm.gold)"
                        checkLabel.attributedText = String().wn_textChangeColor("\(m.diffDay) days left\nCheck-in \(m.checkDay) days", "Check-in \(m.checkDay) days", "", .init(named: "red_CD597C")!, .wn_font(name: .bold, size: 18))
                        payLabel.text = "Get \(sm.gold) Golds"
                    }
                }else {
                    sunImage.isHidden = false
                    totleLabel.text = "Total:\n\(sm.days*sm.gold)"
                    checkLabel.attributedText = String().wn_textChangeColor("Daily check-in gift \n\(sm.gold) Golds per day", "\(sm.gold) Golds per day", "", .init(named: "red_CD597C")!, .wn_font(name: .bold, size: 18))
                    payLabel.text = "USD \(sm.price) / month"
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(bgImage)
        addSubview(sunImage)
        bgImage.addSubview(totleLabel)
        bgImage.addSubview(totleLabel)
        bgImage.addSubview(checkLabel)
        bgImage.addSubview(payLabel)
        bgImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(0)
            make.width.equalTo(scaleWidth(375))
            make.height.equalTo(scaleWidth(162))
        }
        sunImage.snp.makeConstraints { make in
            make.top.right.equalTo(-20)
            make.width.height.equalTo(60)
        }
        totleLabel.snp.makeConstraints { make in
            make.top.equalTo(12)
            make.left.equalTo(24)
        }
        checkLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(32)
        }
        payLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
